import axios from "axios";
import evn from "./env";
// import { showLoadingToast } from "vant";
import { showLoadingToast, closeToast } from "vant";
const instans = axios.create({
  baseURL: evn.load.baseURL,
  timeout: 5000,
});
// 请求拦截
instans.interceptors.request.use(
  (config) => {
    // console.log("请求成功", config);

    showLoadingToast({
      message: "加载中...",
      forbidClick: true,
      loadingType: "spinner",
      overlay: true,
    });

    return config;
  },
  (error) => {
    // console.log("请求失败", error);
    return Promise.reject(error);
  }
);
// 响应拦截
instans.interceptors.response.use(
  (res) => {
    // console.log("响应成功", res);
    closeToast({
      closeAll: true,
    });
    return res.data;
  },
  (error) => {
    // console.log("响应失败", error);
    return Promise.reject(error);
  }
);
export default instans;
